package com.lc.app.hearthstonecards.userdefine.view;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapShader;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Matrix;
import android.graphics.Paint;
import android.graphics.RectF;
import android.graphics.Shader;
import android.graphics.drawable.BitmapDrawable;
import android.view.View;
import android.widget.ImageView;

import com.lc.app.hearthstonecards.R;

/**
 * Created by LC on 12/21/2015.
 */
public class HearthStoneView  extends View{
    public HearthStoneView(Context context) {
        super(context);
    }

    @Override
    protected void onDraw(Canvas canvas) {
        Paint p = new Paint();
        p.setAntiAlias(true);
        ImageView imageView = new ImageView(getContext());
        imageView.setImageResource(R.drawable.banner_hearthstone);
        Bitmap bitmap =( (BitmapDrawable)imageView.getDrawable()).getBitmap();
     //   canvas.translate(80, 60);
        p.setStyle(Paint.Style.FILL);
        p.setStrokeWidth(2);

        RectF rect1 = new RectF(0,0,bitmap.getWidth(),bitmap.getHeight());
        canvas.drawRoundRect(rect1, 1, 1, p);

//        Matrix matrix = new Matrix();
//        matrix.setScale(0.8f,0.8f);
//        Bitmap newBitmap = Bitmap.createBitmap(bitmap,0,0,bitmap.getWidth(),bitmap.getHeight(),matrix,true);
        BitmapShader shader = new BitmapShader(bitmap, Shader.TileMode.REPEAT, Shader.TileMode.MIRROR);
        p.setShader(shader);
        p.setShader(shader);
        canvas.drawRoundRect(rect1, bitmap.getWidth()/2, bitmap.getHeight()/2, p);
    }
}
